<template>
    <div class="room-manage">
        <div class="personal-manage-title">参数配置-利云酒吧
        </div>
        <div class="report-table-wrapper">
            <el-table
                :header-cell-style="headerCellStyle"
                size="small"
                :data="showList"
                border
                style="width: 100%"
            >
                <el-table-column label="类型">
                    <template slot-scope="scope">
                        <span v-show="scope.row.id === 1">ktv</span>
                        <span v-show="scope.row.id === 2">利云酒吧</span>
                    </template>
                </el-table-column>
<!--                <el-table-column prop="hasFyMinPoint" label="有锋云最小点数设置"></el-table-column>
                <el-table-column prop="noFyMinPoint" label="无锋云最小点数设置"></el-table-column>
                <el-table-column prop="maxPoint" label="注册最大点数（单位点）"></el-table-column>
                <el-table-column prop="memoryClouds" label="视易云存储默认延长保存天数"></el-table-column> -->
                <!-- <el-table-column prop="memoryBusiness" label="商家云存储默认赠送天数"></el-table-column> -->
                <el-table-column prop="authMaxPoint" label="特殊授权最大点数"></el-table-column>
                <el-table-column prop="yjSoftPresentYears" label="默认软件赠送有效期"></el-table-column>
                <el-table-column prop="yjCanSearchDays" label="数据可查默认天数"></el-table-column>
                <el-table-column label="操作" width="75">
                    <template slot-scope="scope">
                        <el-button
                            size="mini"
                            type="primary"
                            @click="toSet(scope.$index, scope.row)"
                        >详情</el-button>
                    </template>
                </el-table-column>
            </el-table>
        </div>
        <div class="page-padding"></div>
        <el-dialog title="编辑参数设置" :visible.sync="showEdit">
            <el-form ref="form" size="small" :model="form" label-width="240px">
                <el-form-item label="编辑参数类型:">
                    <!-- <span v-show="form.id === 1">ktv</span> -->
                    <span>利云酒吧</span>
                </el-form-item>
                <!-- <el-form-item label="有锋云最小点数设置:">
                    <el-input size="small" v-model="form.hasFyMinPoint"></el-input>
                </el-form-item>
                <el-form-item label="无锋云最小点数设置:">
                    <el-input size="small" v-model="form.noFyMinPoint"></el-input>
                </el-form-item>
                <el-form-item label="注册最大点数（单位点）:">
                    <el-input size="small" v-model="form.maxPoint"></el-input>
                </el-form-item>
                <el-form-item label="视易云存储默认延长保存天数:">
                    <el-input size="small" v-model="form.memoryClouds"></el-input>
                </el-form-item> -->
                <!-- <el-form-item label="商家云存储默认赠送天数:">
                    <el-input size="small" v-model="form.memoryBusiness"></el-input>
                </el-form-item> -->
                <el-form-item label="特殊授权最大点数:">
                    <!-- <el-select filterable allow-create v-model="form.authMaxPoint" placeholder="请选择" size="small">
                        <el-option v-for="item in options3" :key="item" :label="item" :value="item"></el-option>
                    </el-select> -->
                    <el-input size="small" v-model="form.authMaxPoint"></el-input>
                </el-form-item>
                <el-form-item label="默认软件赠送有效期:">
                    <el-input size="small" v-model="form.yjSoftPresentYears"></el-input>
                </el-form-item>
                <el-form-item label="数据可查默认天数:">
                    <!-- <el-select filterable allow-create v-model="form.authMaxPoint" placeholder="请选择" size="small">
                        <el-option v-for="item in options3" :key="item" :label="item" :value="item"></el-option>
                    </el-select> -->
                    <el-input size="small" v-model="form.yjCanSearchDays"></el-input>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" size="small" @click="onSubmit">保存</el-button>
                    <el-button plain type="primary" size="small" @click="showEdit=false">取消</el-button>
                </el-form-item>
            </el-form>    
        </el-dialog>
    </div>
</template>

<script type="text/ecmascript-6">
// 1、一页20条数据
// 2、勾选框和下拉框和输入框做判断
export default {
    data: function () {
        return {
            showList: [],
            showEdit: false,
            form: {
                noFyMinPoint: 1,
                hasFyMinPoint: 1,
                maxPoint: 1,
                memoryClouds: 1,
                memoryBusiness: 1,
                authMaxPoint: '',
                yjSoftPresentYears: 10, // 默认软件赠送有效期
                yjCanSearchDays: 35 // 数据可查默认天数
            },
            options3: [
                25,
                26,
                27,
                28,
                29,
                30,
                31,
                32,
                33,
                34,
                35,
                36,
                37,
                38,
                39,
                40,
                41,
                42,
                43,
                44,
                45,
                46,
                47,
                48,
                49,
                50
            ]
        }
    },
    components: {
    },
    mounted () {
    },
    created () {
        this.getPage()
    },
    watch: {
    },
    methods: {
        toSet (index, row) {
            this.form = row
            this.showEdit = true
        },
        getPage () {
            let params = {
                params: {
                }
            }
            this.$http.get(this.$store.state.IP + '/agent/list', params).then(response => {
                console.log('-------------------------------------------')
                console.log('调用设置列表返回')
                response = response.body
                console.log(response)
                if (response.ret === '0') {
                    this.showList = response.data
                    console.log('调用设置列表成功')
                }
                if (response.ret !== '0') {
                    console.log('调用设置列表失败')
                }
                console.log('******************************************')
            }, response => {
                console.log('通讯失败')
            })
        },
        onSubmit () {
            if (this.isNumChar(parseInt(this.form.noFyMinPoint))) {
                this.$message({
                    message: '无锋云最小点数，不能为空，必须是数字，最小为1',
                    type: 'warning'
                })
                return
            }
            if (this.isNumChar(parseInt(this.form.hasFyMinPoint))) {
                this.$message({
                    message: '有锋云最小点数，不能为空，必须是数字，最小为1',
                    type: 'warning'
                })
                return
            }
            if (this.isNumChar(parseInt(this.form.maxPoint))) {
                this.$message({
                    message: '注册最大点数，不能为空，必须是数字',
                    type: 'warning'
                })
                return
            }
            if (this.isNumChar(parseInt(this.form.memoryClouds))) {
                this.$message({
                    message: '循环存储时长云端，不能为空，必须是数字',
                    type: 'warning'
                })
                return
            }
            if (this.isNumChar(parseInt(this.form.memoryBusiness))) {
                this.$message({
                    message: '循环存储时长商家，不能为空，必须是数字',
                    type: 'warning'
                })
                return
            }
             if (this.isNumChar(parseInt(this.form.authMaxPoint)) || parseInt(this.form.authMaxPoint) > 999) {
                this.$message({
                    message: '特殊授权最大点数，不能为空，必须是数字，不能大于三位',
                    type: 'warning'
                })
                return
            }
            let suffix = ''
            if (this.form.id === 1) {
                suffix = '/agent/optParamer'
            }
            if (this.form.id === 2) {
                suffix = '/agent/optBarParamer'
            }
            this.$http
                .post(
                    this.$store.state.IP + suffix,
                    {
                        data: this.form
                    },
                    {
                        emulateJSON: false
                    }
                )
                .then(
                    response => {
                        console.log(
                            '-------------------------------------------'
                        )
                        response = response.body
                        console.log(response)
                        if (response.ret === '0') {
                            console.log('调用修改设置成功')
                            console.log(response.data)
                            this.$message({
                                message: '修改设置成功',
                                type: 'success'
                            })
                            this.showEdit = false
                        }
                        if (response.ret !== '0') {
                            //						this.$message.error('修改密码失败')
                            console.log('调用修改设置失败')
                        }
                        console.log(
                            '******************************************'
                        )
                    },
                    response => {
                        console.log('通讯失败')
                    }
                )
        }
    }
}
</script>

<style lang="stylus" rel="stylesheet/stylus">
.room-manage
    width: 100%
    background #fff
    min-height calc(100vh - 65px)

    .personal-manage-title
        width: 100%
        height: 64px
        line-height: 64px
        color: #000
        font-size: 18px
        background #f1f0f5
        position: relative

    .password-set-manage
        width: 100%
        min-height: 370px
        background: #fff

    .page-padding
        width: 100%
        height: 150px
        background: #fff
</style>
